<template>
<Select v-model="selValue" :multiple="multiple" @on-change='specialChange'>
	<Option v-if="multiple" value="全部">全部</Option>
	<Option v-else value="">请选择</Option>
	<Option v-for="item in list" :value="item[field]" :key="item.id">{{ item.sx_name }}</Option>

</Select>
</template>
<script>
export default {
	data:function(){
		return{		
			list:[],
			selValue:null,

		};
	},
	props:{
		value:{
			default:''
		},
		field:{
			default:'id'
		},
		multiple:{
			default:false
		}
	},
	created:function(){
	
		this.init();
		
		
		this.load_data();
	},
	watch:{
		value(val){
			this.init();
		},
		selValue(val){
			
			if(this.multiple && typeof(val)=='object'){
				var ls_val = val.join(',');
			}
			else{
				var ls_val = val;
			}
			this.$emit('input',ls_val);
		}
	},
	methods:{
		init(){
			if(!this.multiple){
				this.selValue = this.value;
			}
			else{
				this.selValue = this.value.split(',');
			}
		},
		load_data(){
			var self = this;
			var postdata = {};
			
			Whttp.load('User/Company/get_all',postdata,function(result){
				self.list = result;
				self.init();
			});
		},
		specialChange(val){
			if(!this.multiple){
				return;
			}
			if(val.indexOf("全部") != -1){
				var arr = [];
				for(var i=0;i<this.list.length;i++){
					arr.push(this.list[i]['sx_name']);
				}
				this.selValue = arr;
				//this.selValue = ["全部","廣州風資"];
			}else{
				return;
			}
		}
	}
}
</script>
<style scoped>

</style>